var app = getApp();
Component({
    properties: {
        info: Object,
        isPush : Boolean,
        liveid : Number,
        params : Object,
    },
    data: {
        isShowInput : false,
        isshow : true,
        content : '',
        chatMessages : [],
        isauth : true,
        toView : 0,
    },
    options : {
        addGlobalClass : true,
    },
    ready: function() {
        var self = this;
    },
    methods: {
        onShow(){
            this.setData({
                isshow : !this.data.isshow
            })
        },
        input : function( e ){
            this.setData({
                content : e.detail.value,
            })
        },
        startinput(){
            this.setData({
                isShowInput : true,
            })
            this.triggerEvent('showbag', 1);
            this.triggerEvent('showbotbar', 1);
        },
        cancelinput(){
            this.setData({
                isShowInput : false,
            })
            this.triggerEvent('showbag', 2);
            this.triggerEvent('showbotbar', 2);
        },
        clear(){
            this.setData({
                chatMessages : [],
                toView : 0,
            })
        },
        send(){
            var self = this;
            if(!self.data.content){
                app.com.toast('还没有填写内容');
                return false;
            }

            if(self.data.info.isauth == 1 && self.data.isauth){
                self.loginauth = this.selectComponent('#loginauth');
                self.loginauth.hideauth();
                return false;
            }

            var postdata = {
                op : 'submess',
                content : self.data.content,
                liveid :  self.data.info.id,
            };
            
            app.com.http('live','POST',postdata,0,true,'','',function(res){
                if ( !res.data.errno && res.data.errno !== undefined ) {
                    self.setData({
                        content : '',
                    })
                    app.com.sendGo(res.data.data.mess,res.data.data.channel);
                    app.com.toast(res.data.message);
                }else{
                    app.com.alert(res.data.message);
                }
            });
        },
        addMessage(mess){
            let self = this;
            self.data.chatMessages.push(mess);
            self.setData({
                chatMessages : self.data.chatMessages,
                toView : self.data.chatMessages.length-1,
            })
        },
        authed(e){
            var self = this;
            self.setData({
                isauth : false,
            })
            setTimeout(function(){
                self.send();
            },50)
        },
    }

})